'use strict';

const await = require('await-stream-ready/lib/await');
const BaseController = require('./base');
/**
 * @Controller 广告模块
 */
class AdController extends BaseController {
  /**
   * @Router post /api/ad/create
   * @Request body creteAdRequest
   * @Summary 新增广告
   */
  async create() {
    const { ctx, app, service } = this;
    const body = ctx.request.body;
    body.adId = Date.now();
    const result = await service.ad.create(body);
    if (result) {
      this.Success({ message: '新增成功' });
    } else {
      this.Error({ message: '新增失败' });
    }
  }


  /**
   * @Router post /api/ad/page
   * @Request body pageAdRequest
   * @Summary 获取广告分页
   */
   async page() {
    const { ctx, service } = this;
    let body = ctx.request.body;
    const data = await service.ad.page(body);
    if (data) {
      this.Success({ data, message: '获取成功' });
    } else {
      this.Error({ message: '获取失败' });
    }
  }

  /**
   * @Router post /api/ad/info
   * @Request body infoAdRequest
   * @Summary 获取广告详情信息
   */
  async info() {
    const { ctx, service } = this;
    let body = ctx.request.body;
    const data = await service.ad.info(body);
    if (data) {
      this.Success({ data, message: '获取成功' });
    } else {
      this.Error({ message: '获取失败' });
    }
  }

  /**
   * @Router post /api/ad/edit
   * @Request body editAdRequest
   * @Summary 修改广告信息
   */
  async edit() {
    const { ctx, service } = this;
    let body = ctx.request.body;
    const data = await service.ad.edit(body);
    if (data) {
      this.Success({ message: '修改成功' });
    } else {
      this.Error({ message: '修改失败' });
    }
  }
  

    /**
   * @Router post /api/ad/del
   * @Request body delAdRequest
   * @Summary 删除广告信息
   */
  async del() {
    const { ctx, service } = this;
    let body = ctx.request.body;
    const data = await service.ad.del(body);
    if (data) {
      this.Success({ message: '删除成功' });
    } else {
      this.Error({ message: '删除失败' });
    }
  }

}

module.exports = AdController;
